<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="root">
        <one></one>
    </div>

    <template id="one1">
        <div>
            <p>1--{{xi}}</p>
            <button @click="send">传递</button>
            <two></two>
        </div>


    </template>

    <template id="two1">
        <div>
            <p>2</p>
            <three></three>

        </div>

    </template>

    <template id="three1">
        <p>3--{{xi}}</p>
    </template>

    <script src="./vue.js"></script>
    <script>
        //阻止vue在启动时生成生产提示
        Vue.config.productionTip = false;
        const bus = new Vue();

        const three = {
            template: '#three1',
            data(){
                return{
                    xi:null,
                }
            },
            mounted() {
                bus.$on('send',(d)=>{
                    this.xi=d;
                })
            },
            beforeDestroy() {
                bus.$off('send');
            },
        }
        const two = {
            template: '#two1',
            components: { three, }
        }
        const one = {
            template: '#one1',
            components: { two, },
            data() {
                return {
                    xi: '嘻嘻哈哈我是小妖怪',
                }
            },
            methods: {
                send() {
                    bus.$emit('send', this.xi);
                }
            },
        }
        //创建vue实例
        new Vue({
            el: '.root',
            data: function () {
                return {
                    name: '',
                }
            },
            components: { one, }
        })
    </script>
</body>

</html>